<?php

namespace app\album\controller;

use cmf\controller\HomeBaseController;

//class IndexController extends HomeBaseController
//{
//    public function index()
//    {
//        return $this->fetch(':index');
////        echo "this is blog index";
//    }
//}
/**
 * Class LoginController
 */
class LoginController extends HomeBaseController
{
    public function index()
    {
        return $this->fetch(':register');
       //echo "this is blog index";
    }

    /**
     * 用户注册
     */
    public function register()
    {
        if(IS_POST){
           //实例化user对象
            $user = D('users');

            //自动验证，创建数据集
            if(!$data = $user->create()){
               //防止中文乱码
                header('Content-type: text/html; charset=utf-8');
                exit($user->getError);
            }

            //插入数据库
            if($id = $user->add($data)){
                $this->success('注册成功');
            }else{
                $this->error('注册失败');
            }
        }else{
            $this->display();
        }
    }
}